package com.example.controller;

import com.example.model.Blog;
import com.example.model.ResponseData;
import com.example.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/blog")
public class BlogController2 {
    @Autowired
    private BlogService blogService;
    @GetMapping
    public ResponseData getBlog(){
        return new ResponseData(200,"success",blogService.selectBlog());
    }
    @GetMapping("/id/{id}")
    public ResponseData getBlogByID(@PathVariable Integer id){
        return new ResponseData(200,"success",blogService.selectBlogByID(id));
    }
    @GetMapping("/title")
    public ResponseData getBlogByTitle(@RequestParam("title") String title){
        Map<String,Object> map=new HashMap<>();
        map.put("title",title);
        return  new ResponseData(200,"success",blogService.selectBlogByTitle(map));
    }


}
